package com.steak.stock.execute;

import com.steak.common.domain.dataobject.tcc.Stock;
import com.steak.common.result.Response;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/116:39
 */
@Component
@AllArgsConstructor
public class StockExecute {

    private final JdbcTemplate jdbcTemplate;

    public Response execute(Stock stock) throws InterruptedException {
        String sql = "UPDATE stock SET stock_num = ( SELECT sto.stock_num FROM ( SELECT ( st.stock_num - "+stock.getStockNum()+" ) stock_num FROM stock st WHERE st.commodity_id = "+stock.getCommodityId()+" ) sto) WHERE commodity_id = "+stock.getCommodityId()+"";
        jdbcTemplate.update(sql);
        return new Response(200,"increase integral success",null);
    }

    public Response get() {
        Map<String, Object> map = jdbcTemplate.queryForMap("select * from stock");
        return new Response(200,"increase integral success",null);
    }
}
